<template>
  <div class="roomGeneralViewManagement clearfix">
    <el-row>
      <el-scrollbar>
      <el-form
        :inline="true"
        class="demo-form-inline toolbar"
        style="padding-bottom:0px;"
        :size="size"
        @submit.native.prevent
      >
        <el-form-item v-for="(item,index) in buildList" :key="index">
          <kt-button
            class="formItemButton"
            :class="{'buttonActive':isActive==index}"
            :label="item.buildingName"
            @click="handleCtrl(item,index)"
          />
        </el-form-item>
      </el-form>
      <div class="filtersposition"></div>
      </el-scrollbar>
    </el-row>
    <div class="roomItem" v-for="(item,index) in roomList" :key="index">
      <!-- by guo 2020-3-13-10:48修改 -->
      <!-- <div class="roomItem-room">{{item.roomNo}}({{item.id}})</div> -->
       <div class="roomItem-room">{{item.roomNo}}</div>
      <!-- <div class="roomItem-div" :class="{'roomItem-div-active':item.alarmFlag==true}" style="background:#ffffff" @click="handleRoomItem(item,index)"> -->
      <div class="roomItem-div" @click="handleRoomItem(item,index)">
        <div class="roomItem-div-img">
          <el-carousel :interval="2000" trigger="click" :autoplay="false" :ref="'carousel' + index" indicator-position="none" arrow="never">
            <el-carousel-item v-for="(temp,index2) in item.img" :key="index2" :style="{background:temp.background}" class="carousel-item-active">
              
              <img v-if="temp.alarmMsg == ''" :src="temp.images" alt="" style="height:90%;margin:0 auto; padding-top:6px;max-width: 120px;object-fit: scale-down;">
              <img v-else :src="temp.images" alt="" style="height:60%;margin:0 auto; padding-top:2px;max-width: 100px;object-fit: scale-down;">
              
              <!-- by guo 2020-3-16-13:24修改  需求变更 去掉温度的显示  修改为对应报警的文字 -->
              <div class="roomItem-div-text" style="margin:0 auto; overflow:hidden;align-items: center;display: flex;justify-content: center;" :title="temp.alarmMsg">
                <p v-html="temp.alarmMsg"></p>
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
        <!-- by guo 2020-3-16-13:24修改  需求变更 去掉温度的显示  修改为对应报警的文字 -->
        <!-- <div class="roomItem-div-text" v-if="item.temperature!=null"><span>{{roomGeneralViewManagement.roomTemperature}}:</span><span>{{item.temperature}}</span><span>℃</span></div>
        <div class="roomItem-div-text" v-else><span>{{roomGeneralViewManagement.roomTemperature}}:</span><span>--</span></div> -->
        
      </div>
    </div>
  </div>
</template>
<script>
import KtButton from "@/components/KtButton";
import bus from "../../../vuex/eventBus"; //引入eventBus,接收子界面传递的跳转指令,然后在父界面跳转,添加tab
import camera from '../../../assets/lifeGroupimg/camera.png';//摄像头跌倒
import gongcebaojiejiankong from '../../../assets/lifeGroupimg/gongcebaojiejiankong.png';//公测报警
import gou from '../../../assets/lifeGroupimg/gou.png';//无报警的图片（勾）
import oldman from '../../../assets/lifeGroupimg/oldman.png'//老人外出
import renTiGanYing from '../../../assets/lifeGroupimg/renTiGanYing.png';//人体感应
import thermometer from '../../../assets/lifeGroupimg/thermometer.png';//温湿度计
import xindian from '../../../assets/lifeGroupimg/xindian.png';//呼吸和心率
import backBed from '../../../assets/lifeGroupimg/backBed.png';//离床
import paihuai from '../../../assets/lifeGroupimg/paihuai.png';//徘徊走动
import shuaidao from '../../../assets/lifeGroupimg/shuaidao.png';//摔倒

//by guo 2020-3-16-11:19添加
import backBedtwo from '../../../assets/lifeGroupimg/backBedtwo.png';//离床报警
import indoor from '../../../assets/lifeGroupimg/indoor.png';//在室
import cameraOff from '../../../assets/lifeGroupimg/cameraOff.png';//摄像头离线
import gatewayOff from '../../../assets/lifeGroupimg/gatewayOff.png';//网关离线
import humidistatOff from '../../../assets/lifeGroupimg/humidistatOff.png';//温度计离线
import sensorOff from '../../../assets/lifeGroupimg/sensorOff.png';//人感离线
import sleepOff from '../../../assets/lifeGroupimg/sleepOff.png';//床垫离线
import qiangzhistop from '../../../assets/lifeGroupimg/caozuo_qiangzhitingzhi.png';//床垫离线
import statusinbed from '../../../assets/lifeGroupimg/life_status_inbed.png';//再床
import statusoutbed from '../../../assets/lifeGroupimg/life_status_outbed.png';//离床
import nightAlertWatch from '../../../assets/lifeGroupimg/nightAlertWatch.png';//夜间巡视异常
import diviceNot from '../../../assets/lifeGroupimg/diviceNot.png';//设备未知
import deviceStop from '../../../assets/lifeGroupimg/life_stop.png';//停止图标

import backBedthree from '../../../assets/lifeGroupimg/backBedthree.png';//新的离床报警 by guo 2020-7-1-11:37新增
import nightAlertWatchTwo from '../../../assets/lifeGroupimg/nightAlertWatchTwo.png';//新的夜间巡视异常 by guo 2020-7-1-11:37新增
export default {
  name: "RoomGeneralViewManagement",//RoomGeneralViewManagement
  data() {
    return {
      roomGeneralViewManagement: this.$t("m.roomGeneralViewManagement"), //引入 lang 里面的字符串资源,
      size:"medium",//按钮的尺寸
      isActive:0,//默认第一个被选中  通过点击来切换  被点击的就给一个被选中的样式
      buildList:[],//查询所有的楼栋
      roomList:[],//格式:{id:'1',roomNo:"101号室(01)",temperature:"室温:25.43c",img:[gou],alarm:false,},{id:'2',roomNo:"101号室(01)",temperature:"室温:25.43c",img:[renTiGanYing,oldman,camera,thermometer,xindian],alarm:true,}, 
      buildingId:"",
      actionrun:null,
      timeOne:null,
      timeTwo:null,
      acceptLanguage:'ja_JP',//数据请求传参需要传的语言  ja_JP----日文
    };
  },
  methods: {
    /* 
      选择不同的楼层 
    */
    handleCtrl(item,index){
      console.log('------------',item);
      this.isActive=index;
      this.buildingId=item.buildingId;
      this.LifeIndexRooms(item.buildingId);
    },

    /*  
      点击房间跳转到房间详情
    */
    handleRoomItem(item,index){
      console.log(item);
      // //通过oldmanId来判断房间是否住人 
      // if(item.oldmanId!=null){
        sessionStorage.setItem("lifeRoomDetail_roomId",item.id);
        bus.$emit("homePage", {
          type: "jump",
          path: "/RoomGeneralViewDetail",
          title: this.roomGeneralViewManagement.roomGeneralViewTilte,
        });
      // }else{
      //   this.$message({message:"房间未居住老人",type:"error"})
      // }
    },
    /* 
      查询每个房间页面的报警色是否设置  hintTypeId==4
    */
    queryAlarmColor(){
      this.$postForm(this.ports.facilityManagement.queryAlarmColor,{},this.acceptLanguage).then(res=>{
        if(res.code==200){
          if(res.result!=null){
            res.result.forEach(item=>{
              if(item.hintTypeId==4){
                this.background=item.color;
              }
            })
          }
        }
      })
    },
    /* 
      获取所有的楼栋 显示的第一条数据
    */
    showDefaultBuild() {
      this.$postForm(this.ports.roomGeneralViewManagement.showAllBuild,{},this.acceptLanguage).then(res => {
        if (res.result != null) {
          for( var i=0;i<res.result.length;i++){
            if(i==0){
              this.buildingId=res.result[0].buildingId
              break;
            }
          }
        } 
        this.LifeIndexRooms(this.buildingId);
      });
    },

    /* 
      获取所有的楼栋
    */
    showAllBuild() {
      this.buildList=[];
      this.$postForm(this.ports.roomGeneralViewManagement.showAllBuild,{},this.acceptLanguage).then(res => {
        if (res.result != null) {
          this.buildList = res.result;
        } else {
          this.buildList = [];
        }
      });
    },

    /* 
      获取房间列表
    */
    LifeIndexRooms(buildingId) {
      let params=new Object();
      params.buildingId=buildingId;
      this.$postJson(this.ports.roomGeneralViewManagement.lifeIndexRooms,params,this.acceptLanguage).then(res=>{
        this.roomList=[];//清空数据,防止累加,放在请求外面清空会有bug
        if(res.code==200){
          var socketTagList = [];//fzq 点击后发生订阅房间状态变更消息;
          res.result.forEach(item=>{
            socketTagList.push("roomId_"+item.id);
            let roomObj={};
            roomObj.id=item.id;
            roomObj.roomNo=item.roomNo;
            roomObj.temperature=item.temperature;
            roomObj.breath=item.breath;
            roomObj.inBed=item.inBed;
            roomObj.heartbeat=item.heartbeat;
            //roomObj.inRoom=item.inRoom;
            roomObj.oldName=item.oldName;
            roomObj.oldmanId=item.oldmanId;
            roomObj.img=new Array();
            roomObj.alarm=new Array();
            roomObj.alarmFlag=Boolean;
            roomObj.isDeviceEnough=item.isDeviceEnough;//isDeviceEnough房间是否包含摄像头、人感、床垫  0-不足 1-足够   by guo 2020-3-20-10:32添加
            roomObj.inRoom=item.isInRoom;//isInRoom 老人是否在房 in-在 out-不在 unknow-设备不足 无法判断   by guo 2020-3-20-10:32添加
            
            // item.buttonStatus == 'enable';
            // 显示图标 不显示其他报警.显示离线报警

            //statusinbed//再床
            //statusoutbed 離床
             

            if(item.isAlertStatus == "yes"){
              //停止图标;
              roomObj.img.push({'images':deviceStop,'alarmMsg':this.roomGeneralViewManagement.devicestop,isbgFlag:true,'background':"#ffffff"});
              roomObj.background="#ffffff";
             
            }else{
              var isStopShow = false;
              //报警列表
              var isShowOfflineAlert = true;
              var isHaveLevelBedAlert = false;
              if(item.buttonStatus == 'enable'){
                  isStopShow = true;
              }
              if(item.isDeviceEnough == 1 && item.isRoomStatus == "yes" && item.isInRoom == "unknow"){
                isShowOfflineAlert = false;
              }
              if(item.deviceAlert!=null && item.deviceAlert.length!=0){
                item.deviceAlert.forEach(item=>{
                  //根据报警类型显示不同的图片 10----床垫离线报警 11----离床报警  12----温湿度异常报警   13-----摄像头跌倒报警 14-----"厕所检测时间到达人感注意时间"(人感)  15-----"厕所检测时间到达人感警告时间"(人感)  16------"厕所检测时间到达人感异常时间"(人感)  17-----呼吸异常  18-----心跳异常  20-----夜间巡视异常（离房报警）21-----摄像头离线  22-----人感离线   23-----网关离线  24-----温度计离线
                  switch(item.alertType){
                    case 10:
                      if(isShowOfflineAlert){
                        if(item.isHandle==false){
                        roomObj.img.push({'images':sleepOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff"; 
                        }else{
                        roomObj.alarm.push(false);
                        }
                      }
                      break;
                    case 11:
                      if(!isStopShow&&item.isHandle==false){ 
                        isHaveLevelBedAlert = true;
                        roomObj.img.push({'images':backBedthree,'alarmMsg':this.roomGeneralViewManagement.alarmMsgEleven,'background':this.background});//by guo 2020-7-1-11:39添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    case 12:
                      if(!isStopShow&&item.isHandle==false){
                        roomObj.img.push({'images':thermometer,'alarmMsg':this.roomGeneralViewManagement.alarmMsgTwelve,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    case 13:
                      if(!isStopShow&&item.isHandle==false){
                        //摔倒
                        roomObj.img.push({'images':shuaidao,'alarmMsg':this.roomGeneralViewManagement.alarmMsgThirteen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    //*alertType=14和15不需要显示图片  16才添加图片
                    case 16:
                      if(!isStopShow&&item.isHandle==false){
                        roomObj.img.push({'images':gongcebaojiejiankong,'alarmMsg':this.roomGeneralViewManagement.alarmMsgSixteen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    case 17:
                      if(!isStopShow&&item.isHandle==false){
                        //心电
                        roomObj.img.push({'images':xindian,'alarmMsg':this.roomGeneralViewManagement.alarmMsgSeventeen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    //by guo 2020-3-4-18:57添加 需求变更 呼吸（17）和心跳（18）的报警拆分
                    //by guo 2020-3-9-11:56注释  需求变更  呼吸和心跳又合并为1个
                    case 20:
                      if(!isStopShow&&item.isHandle==false){
                        //夜间报警监控
                        roomObj.img.push({'images':nightAlertWatchTwo,'alarmMsg':this.roomGeneralViewManagement.alarmMsgTwenty,'background':this.background});//by guo 2020-7-1-11:41添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                    case 21:
                      if(isShowOfflineAlert){
                      if(item.isHandle==false){
                        roomObj.img.push({'images':cameraOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }else{
                        roomObj.alarm.push(false);
                      }
                      }
                      break;
                    case 22:
                      if(isShowOfflineAlert){
                      if(item.isHandle==false){
                        roomObj.img.push({'images':sensorOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }else{
                        roomObj.alarm.push(false);
                      }
                      }
                      break;
                    //by guo 2020-3-16-13:17添加 网关离线报警
                    case 23:
                      if(isShowOfflineAlert){
                      if(item.isHandle==false){
                        roomObj.img.push({'images':gatewayOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }else{
                        roomObj.alarm.push(false);
                      }
                      }
                      break;
                    //by guo 2020-3-16-13:17添加 温度计离线报警
                    case 24:
                      if(!isStopShow&&item.isHandle==false){
                        roomObj.img.push({'images':humidistatOff,'alarmMsg':this.roomGeneralViewManagement.alertTypeTwentyfour,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }else{
                        roomObj.alarm.push(false);
                      }
                      break;
                  }
                })
              }
              
              if(isStopShow){
                roomObj.img.push({'images':qiangzhistop,'alarmMsg':this.roomGeneralViewManagement.devicemuststop,isbgFlag:true,'background':"#FB8282"});
                roomObj.background="#ffffff";
                roomObj.alarm.push(true);
              }else{
                if(roomObj.inRoom == "inBed"){
                  roomObj.img.push({'images':statusinbed,'alarmMsg':'',isbgFlag:true,'background':"#ffffff"});
                  roomObj.background="#ffffff";
                } else if(roomObj.inRoom == "outBed"){
                  if(isHaveLevelBedAlert == false){
                    roomObj.img.push({'images':statusoutbed,'alarmMsg':'',isbgFlag:true,'background':"#ffffff"});
                    roomObj.background="#ffffff";
                  }
                }else if(roomObj.inRoom=="in"){//在房
                    roomObj.img.push({'images':indoor,'alarmMsg':"",isbgFlag:true,'background':"#ffffff"});//by guo 2020-3-16-13:33修改  √图标变更为 在室图标   不是报警的图标不需要报警色  添加一个标识符 区分isbgFlag:true
                    roomObj.background="#ffffff";
                    roomObj.alarm.push(true);
                }else if((roomObj.inRoom=="out")){//离房
                    roomObj.img.push({'images':oldman,'alarmMsg':this.roomGeneralViewManagement.outRoomMessage,isbgFlag:true,'background':"#ffffff"}); 
                    roomObj.background="#ffffff";
                    roomObj.alarm.push(true);
                }else{
                  if(item.isRoomStatus == "yes"){  //夜间
                    roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceNoMessage,isbgFlag:true,'background':"#ffffff"});//by guo 2020-3-16-13:33修改  √图标变更为 在室图标   不是报警的图标不需要报警色  添加一个标识符 区分isbgFlag:true
                    roomObj.background="#ffffff";
                    roomObj.alarm.push(true);
                  }else{
                    if(item.isDeviceEnough == 0){//设备不全
                      roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,isbgFlag:true,'background':"#ffffff"});
                      roomObj.background="#ffffff";
                      roomObj.alarm.push(true);
                    }else if(item.deviceAlert==null || item.deviceAlert.length == 0){
                      // 正常显示
                      roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,isbgFlag:true,'background':"#ffffff"});
                      roomObj.background="#ffffff";
                      roomObj.alarm.push(true);
                    }
                  }
                }
              }
              roomObj.img=this.uniqueArray(roomObj.img, 'images');//json数组去重  by guo 2020-3-19-9:11
              roomObj.alarm=[...new Set(roomObj.alarm)];//去重
              roomObj.alarmFlag=roomObj.alarm.indexOf(true)!=-1 ? true : false;//alarmFlag==true代表该类型的警报肯定有未处理的
              if(roomObj.alarmFlag==true){
                roomObj.background=this.background;
              }
            }
            this.roomList.push(roomObj);
          });
          console.log(this.roomList);
          var socketMsgContent = {
              "msgType":"subTagMsg",
              "tagList":socketTagList,
              "messageId":this.uuid()
          }
          setTimeout(()=>{
            bus.$emit("homePage", {
              type: "websocket",
              content: JSON.stringify(socketMsgContent),
            });
          },800)
        }
      })
    },
    controlRefreshMsg(msg){
      if(msg.length<13){
        return;
      }
      var item = JSON.parse(msg);
      //1.找到房间号
      //{"alertTypeList":[],"groupId":1017,"inRoom":"unknow","isDeviceEnough":0,"location":"LIFE01-1-00000","roomId":10906}
      // this.roomList
      var changeRoomIndex = -1;
      var changeRoomBean = {};
      for(var i=0;i<this.roomList.length;i++){
        if(this.roomList[i].id == item.roomId){
          changeRoomIndex = i;
          changeRoomBean = this.roomList[i];
          break;
        }
      }
      if(changeRoomIndex == -1){
        return;
      }
      //2.整理数据源
      let roomObj=changeRoomBean;
      roomObj.id=item.roomId;
      roomObj.roomNo=changeRoomBean.roomNo;
      // roomObj.inBed=item.inBed;
      //roomObj.inRoom=item.inRoom;
      roomObj.img.splice(0,roomObj.img.length);
      roomObj.alarm.splice(0,roomObj.alarm.length);
      roomObj.alarmFlag=Boolean;
      roomObj.isDeviceEnough=item.isDeviceEnough;//isDeviceEnough房间是否包含摄像头、人感、床垫  0-不足 1-足够   by guo 2020-3-20-10:32添加
      roomObj.inRoom=item.inRoom;//isInRoom 老人是否在房 in-在 out-不在 unknow-设备不足 无法判断   by guo 2020-3-20-10:32添加
       
      
      if(item.alertStatus == "yes"){
        //停止图标;
        roomObj.img.push({'images':deviceStop,'alarmMsg':this.roomGeneralViewManagement.devicestop,isbgFlag:true,'background':"#ffffff"});
        roomObj.background="#ffffff";
      }else{
        var isStopShow = false;
        //报警列表
        var isShowOfflineAlert = true;
        var isHaveLevelBedAlert = false;
        if(item.buttonStatus == 'enable'){
            isStopShow = true;
        }
        //报警列表
        if(item.isDeviceEnough == 1 && item.showStatus == "yes" && item.inRoom == "unknow"){
          isShowOfflineAlert = false;
        }
        if(item.alertTypeList!=null && item.alertTypeList.length!=0){
          item.alertTypeList.forEach(item=>{
            //根据报警类型显示不同的图片 10----床垫离线报警 11----离床报警  12----温湿度异常报警   13-----摄像头跌倒报警 14-----"厕所检测时间到达人感注意时间"(人感)  15-----"厕所检测时间到达人感警告时间"(人感)  16------"厕所检测时间到达人感异常时间"(人感)  17-----呼吸异常  18-----心跳异常  20-----夜间巡视异常（离房报警）21-----摄像头离线  22-----人感离线   23-----网关离线  24-----温度计离线
            switch(item){
                    case 10:
                      if(isShowOfflineAlert){
                        roomObj.img.push({'images':sleepOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }
                      break;
                    case 11:
                      if(!isStopShow){
                        isHaveLevelBedAlert = true;
                        roomObj.img.push({'images':backBedthree,'alarmMsg':this.roomGeneralViewManagement.alarmMsgEleven,'background':this.background});//by guo 2020-7-1-11:39添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }
                      break;
                    case 12:
                      if(!isStopShow){
                        roomObj.img.push({'images':thermometer,'alarmMsg':this.roomGeneralViewManagement.alarmMsgTwelve,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }
                      
                      break;
                    case 13:
                      if(!isStopShow){
                        roomObj.img.push({'images':shuaidao,'alarmMsg':this.roomGeneralViewManagement.alarmMsgThirteen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }
                      break;
                    //*alertType=14和15不需要显示图片  16才添加图片
                    case 16:
                      if(!isStopShow){
                        roomObj.img.push({'images':gongcebaojiejiankong,'alarmMsg':this.roomGeneralViewManagement.alarmMsgSixteen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                      }
                      break;
                    case 17:
                      if(!isStopShow){
                        //心电
                        roomObj.img.push({'images':xindian,'alarmMsg':this.roomGeneralViewManagement.alarmMsgSeventeen,'background':this.background});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                    
                      }
                      break;
                    //by guo 2020-3-4-18:57添加 需求变更 呼吸（17）和心跳（18）的报警拆分
                    //by guo 2020-3-9-11:56注释  需求变更  呼吸和心跳又合并为1个
                    case 20:
                      if(!isStopShow){
                        //夜间报警监控
                        roomObj.img.push({'images':nightAlertWatchTwo,'alarmMsg':this.roomGeneralViewManagement.alarmMsgTwenty,'background':this.background});//by guo 2020-7-1-11:41添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background=this.background;
                     
                      }
                      break;
                    case 21:
                      if(isShowOfflineAlert){
                        roomObj.img.push({'images':cameraOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }
                      break;
                    case 22:
                      if(isShowOfflineAlert){
                        roomObj.img.push({'images':sensorOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }
                      break;
                    //by guo 2020-3-16-13:17添加 网关离线报警
                    case 23:
                      if(isShowOfflineAlert){
                        roomObj.img.push({'images':gatewayOff,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }
                      break;
                    //by guo 2020-3-16-13:17添加 温度计离线报警
                    case 24:
                      if(!isStopShow){
                        roomObj.img.push({'images':humidistatOff,'alarmMsg':this.roomGeneralViewManagement.alertTypeTwentyfour,'background':"#ffffff"});//by guo 2020-3-16-13:33添加  报警图标和报警提示的文字对应
                        roomObj.alarm.push(true);
                        roomObj.background="#ffffff";
                      }
                      break;
            }
          })
        }

        
        if(isStopShow){
            roomObj.img.push({'images':qiangzhistop,'alarmMsg':this.roomGeneralViewManagement.devicemuststop,isbgFlag:true,'background':"#FB8282"});
            roomObj.background="#ffffff";
            roomObj.alarm.push(true); 
        }else{
          if(item.inRoom == "inBed"){
            roomObj.img.push({'images':statusinbed,'alarmMsg':'',isbgFlag:true,'background':"#ffffff"});
            roomObj.background="#ffffff";
          } else if(item.inRoom == "outBed"){
            if(isHaveLevelBedAlert == false){
              roomObj.img.push({'images':statusoutbed,'alarmMsg':'',isbgFlag:true,'background':"#ffffff"});
              roomObj.background="#ffffff";
            }
          }else if(roomObj.inRoom=="in"){//在房
              roomObj.img.push({'images':indoor,'alarmMsg':"",isbgFlag:true,'background':"#ffffff"});//by guo 2020-3-16-13:33修改  √图标变更为 在室图标   不是报警的图标不需要报警色  添加一个标识符 区分isbgFlag:true
              roomObj.background="#ffffff";
              roomObj.alarm.push(true);
          }else if((roomObj.inRoom=="out")){//离房
              roomObj.img.push({'images':oldman,'alarmMsg':this.roomGeneralViewManagement.outRoomMessage,isbgFlag:true,'background':"#ffffff"}); 
              roomObj.background="#ffffff";
              roomObj.alarm.push(true);
          }else{ //unkown
            if(item.showStatus == "yes"){  //夜间
              roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceNoMessage,isbgFlag:true,'background':"#ffffff"});//by guo 2020-3-16-13:33修改  √图标变更为 在室图标   不是报警的图标不需要报警色  添加一个标识符 区分isbgFlag:true
              roomObj.background="#ffffff";
              roomObj.alarm.push(true);
            }else{
              if(item.isDeviceEnough == 0){//设备不全
                roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,isbgFlag:true,'background':"#ffffff"});
                roomObj.background="#ffffff";
                roomObj.alarm.push(true);
              } else if(item.alertTypeList==null || item.alertTypeList.length == 0){
                // 正常显示
                roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceerrormsg,isbgFlag:true,'background':"#ffffff"});
                roomObj.background="#ffffff";
                roomObj.alarm.push(true);
              }
            }
          }
          // if(item.isRoomStatus == "yes"){  //夜间
          //   if(roomObj.inRoom=="in"){//在房
          //     roomObj.img.push({'images':indoor,'alarmMsg':"",isbgFlag:true,'background':"#ffffff"});//by guo 2020-3-16-13:33修改  √图标变更为 在室图标   不是报警的图标不需要报警色  添加一个标识符 区分isbgFlag:true
          //     roomObj.background="#ffffff";
          //   }else if((roomObj.inRoom=="out")){//离房
          //     roomObj.img.push({'images':oldman,'alarmMsg':this.roomGeneralViewManagement.outRoomMessage,isbgFlag:true,'background':"#ffffff"}); 
          //     roomObj.background="#ffffff";
          //   }else{
          //   }
          // }else{
          //   //不稼働图标,夜间定时循回实施
          //   roomObj.img.push({'images':diviceNot,'alarmMsg':this.roomGeneralViewManagement.deviceNoMessage,isbgFlag:true,'background':"#ffffff"});
          //   roomObj.background="#ffffff";
          // }
        }
        // roomObj.img=this.uniqueArray(roomObj.img, 'images');//json数组去重  by guo 2020-3-19-9:11
        // roomObj.alarm=[...new Set(roomObj.alarm)];//去重
        // roomObj.alarmFlag=roomObj.alarm.indexOf(true)!=-1 ? true : false;//alarmFlag==true代表该类型的警报肯定有未处理的
        // if(roomObj.alarmFlag==true){
        //   roomObj.background=this.background;
        // }
      }
      //3.替换数据源
      this.roomList.splice(changeRoomIndex,1,roomObj);
      console.log(this.roomList);
    },
    //获取messageId
    uuid() {
      let s4 = function() {
          return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
      }
      return (s4() + "1" + s4().substr(0, 3)).toUpperCase();
    },
    /*
    * by guo 2020-3-19-9:11
    * JSON数组去重
    * @param: [array] json Array
    * @param: [string] 唯一的key名，根据此键名进行去重
    */
    uniqueArray(array, key){
      var result = [array[0]];
      for(var i = 1; i < array.length; i++){
        var item = array[i];
        var repeat = false;
        for (var j = 0; j < result.length; j++) {
          if (item[key] == result[j][key]) {
            repeat = true;
            break;
          }
        }
        if (!repeat) {
          result.push(item);
        }
      }
      return result;
    },
  },
  created() {
    //每过2min刷新一次?
    this.timeOne = setInterval(() => {
      this.LifeIndexRooms(this.buildingId);
    }, 20 * 60 * 1000);
    this.timeTwo = setInterval(() => {
      // 找到全部的
      for(var i=0;i<this.roomList.length;i++){
        if(this.roomList[i].img!=null && this.roomList[i].img.length>1){
          var nameStr2 = 'carousel'+i;
          if(this.$refs[nameStr2]!=null && this.$refs[nameStr2][0]!=null){
            this.$refs[nameStr2][0].next();
          }
        }
      }
    }, 2 * 1000);
    //end
    this.queryAlarmColor();
    this.showDefaultBuild();
  },
  activated(){
    //keep-alive 生命周期钩子
    console.log('activated---activated');
    // if(this.buildingId!=null && this.buildingId!=""){
    //   this.LifeIndexRooms(this.buildingId);
    // }
  },
  mounted() {
    this.showAllBuild();
    //change_alarm_color
    this.$bus.$on("change_alarm_color",()=>{
      console.log("接收报警颜色通知")
      this.queryAlarmColor();
      this.LifeIndexRooms(this.buildingId);
    })
    //接收新的房间状态变更通知
    this.$bus.$on("changeLife_roomStatus", msg => {
      // 房间状态更新消息;
      this.controlRefreshMsg(msg);
      // var alertBean=JSON.parse(data.content);
      // this.roomList 中找到这个room,然后替换数据
    });
    // bus.$on("refreshRoomGeneralViewColor",()=>{
    //   console.log("接收到新的报警信息，refreshRoomGeneralViewColor")
    //   this.queryAlarmColor();
    //   this.LifeIndexRooms(this.buildingId);
    // })
    // this.$bus.$on("changeLifeAlarm_websocket",()=>{ //main接收到新的报警信息
    //   console.log("接收到新的报警信息，刷新房间列表的数据")
    //   this.queryAlarmColor();
    //   this.LifeIndexRooms(this.buildingId);
    // })
    // this.$bus.$on("refreshalarmTitle",()=>{ //web端手动处理报警
    //   console.log("接收到房间详情页面报警列表，刷新房间一览房间列表")
    //   this.queryAlarmColor();
    //   this.LifeIndexRooms(this.buildingId);
    // });
    bus.$on("refreshRoomInfoBuild",()=>{
      console.log("接收到设施管理添加楼栋，刷新房间一览的楼栋信息")
      this.queryAlarmColor();
      this.LifeIndexRooms(this.buildingId);
      this.showAllBuild();
    });
    bus.$on("delete_Build",()=>{
      console.log("接收到设施管理删除楼栋的通知,刷新房间一览的楼栋信息")
      this.queryAlarmColor();
      this.LifeIndexRooms(this.buildingId);
      this.showAllBuild();
    });
  },
  destroyed() {
    bus.$off("refreshRoomInfoBuild");
    this.$bus.$off("change_alarm_color");
    bus.$off("delete_Build");
    this.$bus.$off("changeLife_roomStatus");
    //
    clearInterval(this.timeOne);
    clearInterval(this.timeTwo);
  },
  components:{
    KtButton,
  },
};
</script>
<style lang="scss" scoped>
  .roomGeneralViewManagement{
    .toolbar{
      margin: 0px 0px !important;
    }
    .formItemButton{
      border:1px solid #8d8d8d;
      color:#8d8d8d;
    }
    .buttonActive{
      background: #3a77e2;
      color:#fefefe;
    }
    //by guo 2020-3-16-16:31添加
    .roomItem-div-text{
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      font-weight: 600 !important;
    }

    @media (max-width: 1023px){ 
      .roomItem{
        float: left;
        width: 22%;
        height: 140px;
        margin:1.3%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:120px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 80px;
            // line-height: 80px;
            img{
              vertical-align: middle;
            }  
          }
          .roomItem-div-text{
            height:50px;
            // line-height: 22px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 130px;
        }
        /deep/ .el-carousel__container {
          height: 130px;
        }
      }
    }
    @media (min-width: 1024px){ 
      .roomItem{
        float: left;
        width: 22%;
        height: 140px;
        margin:1.3%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:120px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 80px;
            // line-height: 80px;
            img{
              vertical-align: middle;
            }  
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 130px;
        }
        /deep/ .el-carousel__container {
          height: 130px;
        }
      }
    }
    @media (min-width: 1100px) {
      .roomItem{
        float: left;
        width: 22%;
        height: 140px;
        margin:1.3%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:120px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 80px;
            // line-height: 80px;
            img{
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 130px;
        }
        /deep/ .el-carousel__container {
          height: 130px;
        }
      }
    } 
    @media (min-width: 1366px) {
      .roomItem{
        float: left;
        width: 14%;
        height: 150px;
        margin:1.2%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:130px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 70px;
            // line-height: 70px;
            img{
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 130px;
        }
        /deep/ .el-carousel__container {
          height: 130px;
        }
      }
    }  
    @media (min-width: 1440px) {
       .roomItem{
        float: left;
        width: 15%;
        height: 140px;
        margin:0.731%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:120px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 80px;
            // line-height: 80px;
            img{
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4 !important;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 120px;
        }
        /deep/ .el-carousel__container {
          height: 120px;
        }
      }
    }
    @media (min-width: 1600px) {
       .roomItem{
        float: left;
        width: 15%;
        height: 150px;
        margin:0.731%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:130px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 90px;
            // line-height: 90px;
            img{
              width:60%;
              height: 60%;
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 130px;
        }
        /deep/ .el-carousel__container {
          height: 130px;
        }
      }
    }
    @media (min-width: 1680px) {
       .roomItem{
        float: left;
        width: 15%;
        height: 170px;
        margin:0.72%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:150px;
          background: #ffffff;
          color:#343434;
          .roomItem-div-img{
            height: 110px;
            // line-height: 110px;
            img{
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 150px;
        }
        /deep/ .el-carousel__container {
          height: 150px;
        }
      }
    } 
    @media (min-width: 1920px) {
       .roomItem{
        float: left;
        width: 15%;
        height: 170px;
        margin:0.72%;
        border:1px solid #ccc;
        text-align: center;
        .roomItem-room{
          height:20px;
          color:#666666;
        }
        .roomItem-div{
          height:150px;
          background: #ffffff;
          color: #343434;
          .roomItem-div-img{
            height: 110px;
            // line-height: 110px;
            img{
              vertical-align: middle;
            } 
          }
          .roomItem-div-text{
            height:50px;
            font-size: 14px;
            font-weight: 500;
          }
        }
        .roomItem-div-active{
          background: #3a77e2;
          z-index: 9999;
        }
        .roomItem-div:hover{
          background: #bee1f4;
          cursor: pointer;
        }
        //by guo 2020-3-23-9:15添加
        .carousel-item-active{
          background:#fff;
          height: 150px;
        }
        /deep/ .el-carousel__container {
          height: 150px;
        }
      }
    } 
  }
   //by guo 2020-3-28-15:55修改 注释
  // /deep/ .roomItem-div .el-carousel__container {
  //   height: 140px;
  // }
  /deep/ .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view{
    white-space: nowrap;
    width:100%;
    height:100%;
    overflow-x: auto;
  }
  /deep/ .el-form--inline{
    position: relative;
    z-index: 99;
  }
  .filtersposition{
    position: absolute;
    top:-10px;
    left:0;
    right:0;
    bottom:10px;
    width:100%;
    max-height:56px;
    background: #F2F2F2;
    z-index:1;
  }
  //by guo 2020-3-28-15:55修改  去掉屏幕缩放时的房间一览小块的y轴滚动条
  /deep/ .roomItem-div .el-carousel--horizontal{
    overflow-y: hidden;
  }
</style>